_require local "../../../../basis.smi"
(* _require local "../../../../config/main/Config.smi" *)
_require local "../../../data/symbols/main/Loc.smi"
_require local "../../../data/symbols/main/Symbol.smi"
_require local "../../../extensions/debug/main/Bug.smi"
(* _require local "../../../libs/ids/main/LocalID.smi" *)
_require local "../../../extensions/reflection/main/ReifyTopEnv.smi"
_require local "../../../extensions/reflection/main/TopEnvUtils.ppg.smi"

_require local "../../../extensions/userlevelprimitive/main/UserLevelPrimitive.smi"
(* _require local "../../../data/builtin/main/BuiltinTypes.smi" *)
(* _require local "../../../data/types/main/Types.ppg.smi" *)
_require local "../../../data/runtimetypes/main/RuntimeTypes.ppg.smi"
_require local "../../../data/control/main/Control.smi"
_require local "../../../libs/util/main/Counter.smi"
(* _require "../../../libs/toolchain/main/Filename.smi" *)
(* _require local "../../../libs/toolchain/main/TempFile.smi" *)
(* _require local "../../../libs/toolchain/main/BinUtils.smi" *)
_require local "../../../libs/toolchain/main/CoreUtils.smi"
_require "../../../libs/toolchain/main/LLVMUtils.smi"
_require "../../../extensions/usererror/main/UserError.ppg.smi"
_require local "../../../compilerIRs/absyn/main/AbsynInterface.ppg.smi"
_require local "../../../compilerIRs/absyn/main/Absyn.smi"
_require local "../../../compilerIRs/absyn/main/AbsynFormatter.smi"
_require "../../../compilerIRs/absyn/main/InterfaceName.ppg.smi"
_require local "../../../compilerIRs/patterncalc/main/PatternCalcInterface.ppg.smi"
_require local "../../../compilerIRs/idcalc/main/IDCalc.ppg.smi"
(* _require local "../../../data/types/main/VarMap.smi" *)
_require "../../../compilePhases/parser/main/Parser.smi"
(* _require local "../../../compilePhases/parser/main/InterfaceParser.smi" *)
_require local "../../../compilePhases/loadfile/main/LoadFile.smi"
_require local "../../../compilePhases/elaborate/main/Elaborator.smi"
_require local "../../../compilePhases/nameevaluation/main/NameEvalEnv.ppg.smi"
_require local "../../../compilePhases/nameevaluation/main/NameEvalEnvPrims.smi"
_require local "../../../compilePhases/nameevaluation/main/NameEval.smi"
(* _require local "../../../compilePhases/nameevaluation/main/NameEvalUtils.smi" *)
_require local "../../../compilePhases/valrecoptimization/main/VALREC_Optimizer.smi"
_require local "../../../compilePhases/valrecoptimization/main/TransFundecl.smi"
_require local "../../../compilerIRs/typedcalc/main/TypedCalc.ppg.smi"
_require local "../../../compilePhases/typedcalcoptimization/main/TCOptimize.smi"
(* _require local "../../../compilePhases/recordcalcoptimization/main/RCOptimize.smi" *)
_require local "../../../compilePhases/typeinference/main/InferTypes2.smi"
_require local "../../../compilePhases/polytyelimination/main/PolyTyElimination.smi"
_require local "../../../compilePhases/typeinference/main/UncurryFundecl_ng.smi"
(* _require local "../../../compilePhases/typeinference/main/TypeInferenceContext.ppg.smi" *)
(*
_require local "../../../libs/interactivePrinter/main/Reify.smi"
*)
_require local "../../../compilerIRs/recordcalc/main/RecordCalc.ppg.smi"
_require local "../../../compilePhases/matchcompilation/main/MatchCompiler.smi"
_require local "../../../compilePhases/typedelaboration/main/TypedElaboration.smi"
_require local "../../../compilePhases/fficompilation/main/FFICompilation.smi"
_require local "../../../compilePhases/recordcompilation/main/RecordCompilation.smi"
_require local "../../../compilerIRs/typedlambda/main/TypedLambda.ppg.smi"
_require local "../../../compilePhases/datatypecompilation/main/DatatypeCompilation.smi"
_require local "../../../compilerIRs/bitmapcalc/main/BitmapCalc2.ppg.smi"
_require local "../../../compilePhases/bitmapcompilation/main/BitmapCompilation.smi"
_require local "../../../compilerIRs/closurecalc/main/ClosureCalc.ppg.smi"
_require local "../../../compilePhases/closureconversion/main/ClosureConversion2.smi"
_require local "../../../compilerIRs/runtimecalc/main/RuntimeCalc.ppg.smi"
_require local "../../../compilePhases/cconvcompile/main/CallingConventionCompile.smi"
_require local "../../../compilerIRs/anormal/main/ANormal.ppg.smi"
_require local "../../../compilerIRs/anormal/main/ANormalTypeCheck.smi"
_require local "../../../compilePhases/anormalize/main/ANormalize.smi"
_require local "../../../compilerIRs/machinecode/main/MachineCode.ppg.smi"
_require local "../../../compilePhases/machinecodegen/main/MachineCodeGen.smi"
_require local "../../../extensions/concurrencysupport/main/ConcurrencySupport.smi"
_require local "../../../compilePhases/stackallocation/main/StackAllocation.smi"
_require local "../../../compilerIRs/llvmir/main/LLVMIR.ppg.smi"
_require local "../../../compilePhases/llvmgen/main/LLVMGen.smi"
_require local "../../../compilePhases/llvmemit/main/LLVMEmit.smi"
_require local "../../../compilePhases/analyzefiles/main/Analyzers.smi"
_require "./TopData.ppg.smi"
_require local "./NameEvalEnvUtils.smi"

structure Top =
struct
  datatype stopAt = datatype TopData.stopAt
  datatype result = datatype TopData.result
  type options = TopData.options
  type toplevelContext = TopData.toplevelContext
  type newContext = TopData.newContext

  val extendContext : toplevelContext * newContext -> toplevelContext
  val emptyNewContext : newContext

  val compile
      : LLVMUtils.compile_options
        -> options
        -> toplevelContext
        -> Parser.input
        -> InterfaceName.file_dependency * result

  (* Load the given interface files and returns a new environment
   * for codes that require them.
   *)
  val loadInterfaces
      : ['a#{stopAt : stopAt,
             loadPath : InterfaceName.source list,
             loadMode : InterfaceName.file_load_mode,
             outputWarnings : UserError.errorInfo list -> unit}.
         'a
         -> toplevelContext
         -> InterfaceName.source list
         -> InterfaceName.file_dependency * newContext]

  val loadBuiltin
      : InterfaceName.source -> toplevelContext

end
